
// const BASE_URL = 'http://www.kimi2000.com/api'
const BASE_URL = 'http://localhost/api'

const common={
	baseUrl:BASE_URL,
	data:{},
	header:{
		'content-type':'application/json',
		'content-type':'application/x-www-form-urlencoded'
	},
	method:'GET',
	dataType:'json',
	isShowLoading: true
}

const dataObj={
	user_id:'sdfwer3123nkj12h31',
}

export default function $http(options={}){
	options.url=BASE_URL+options.url
	var data = options.data || common.data;
	
	options.data = {
		user_id:'sdfwer3123nkj12h31',
		...data
	}
	options.header = options.header || common.header
	options.method = options.method || common.method
	options.dataType = options.dataType || common.dataType
	options.isShowLoading = options.isShowLoading || common.isShowLoading
	
	if(options.isShowLoading){
		uni.showLoading({
			title:'加载中...'
		})
	}
	
	return new Promise((resolve, reject)=>{
		uni.request({
			...options,
			success:(res)=>{
				if(res.statusCode==200){
					return resolve(res.data);
				}else{
					return reject();
				}
			},
			fail: (err) => {
				uni.showLoading({
					title:'网络请求错误'
				})
				return
			},
			complete: ()=>{
				if(options.isShowLoading){
					uni.hideLoading()
				}
			}
		});
	});
}